#include "STC89C5xRC.h"

#define u16 unsigned int
#define u8  unsigned char
#define beep P23 
#define WELA P27
#define DULA P26

u8 code table[] = {
									0x3f,0x06,0x5b,0x4f,
									0x66,0x6d,0x7d,0x07,
									0x7f,0x6f,0x77,0x7c,
									0x39,0x5e,0x79,0x71,0x00};
void DelayMs(u16 ms);
void DigitalDis(u16 num);

void main()                                                                                            
{
	while(1)
	{
		DigitalDis(45678);
	}
}

void DelayMs(u16 ms)
{
	u16 a,b;
	for(a = ms;a > 0;a--)
		for(b = 114;b > 0;b--);
}

void DigitalDis(u16 num) //num = 45667
{
		P0 = 0xff;
		WELA = 1;
		P0 = 0Xfe;	
		WELA = 0; 
		P0 = 0;
		DULA = 1;
		P0 = table[num / 10000];
		DULA = 0; 
		
		DelayMs(2);
		P0 = 0xff;
		WELA = 1;
		P0 = 0Xfd;
		WELA = 0; 
		P0 = 0;
		DULA = 1;	
		P0 = table[num % 10000 / 1000];
		DULA = 0; 
		
		DelayMs(2);
		P0 = 0xff;
		WELA = 1;
		P0 = 0Xfb;
		WELA = 0;
		P0 = 0;
		DULA = 1;		
		P0 = table[num % 1000 / 100];
		DULA = 0; 
		
		DelayMs(2);
		P0 = 0xff;
		WELA = 1;		
		P0 = 0Xf7;
		WELA = 0; 
		P0 = 0;
		DULA = 1;
		P0 = table[num % 100 /10];
		DULA = 0; 
		
		DelayMs(2);
		P0 = 0xff;
		WELA = 1;
		P0 = 0Xef;
		WELA = 0; 
		P0 = 0;
		DULA = 1;		
		P0 = table[num % 10];
		DULA = 0; 	
		DelayMs(2);
}

